package algorithms;

/**
 * 
 * @author Emanuel Martins 5940, Ana Pontes 5950 || date 05/06/2014
 * 
 *         This is the class FilaEspera, this class sets a queue to be processed
 * 
 */

public class FilaEspera
{
   int   length = 0;
   int[] q      = null;
   int   tail   = 0;
   int   head   = 0;

   public FilaEspera(int n)
   {
      this.length = n - 1;
      this.q = new int[this.length];
      this.tail = 0;
      this.head = 0;
   }

   /**
    * This method puts it on queue
    * 
    * @param x
    *           - value to put on queue
    */

   public void enqueue(int x)
   {
      this.q[this.tail] = x;
      if (this.tail == this.length)
      {
         this.tail = 0;
      }
   }

   /**
    * This method gets it off the queue
    * 
    */

   public int dequeue()
   {
      int x = this.q[this.head];
      if (this.head == this.length)
      {
         this.head = 0;
      }
      else
      {
         this.head = this.head + 1;
      }
      return x;
   }
}
